import java.util.ArrayList;
import java.util.List;

public class combine {

    List<List<Integer>> ans = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        int[] nums = new int[n];
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            nums[i] = i + 1;
        }
        process(nums, 0, list, k);
        return ans;
    }

    public void process(int[] nums, int i, List<Integer> list, int k) {
        if (list.size() + (nums.length - i + 1) < k) return;

        if (list.size() == k || i == nums.length) {
            if (list.size() == k) {
                ans.add(new ArrayList<>(list));
            }
            return;
        }

        list.add(nums[i]);
        process(nums, i + 1, list, k);
        list.remove(list.size() - 1);
        process(nums, i + 1, list, k);
    }
}
